//获取.css .html .js 文件
//导入fs和path模块
const fs = require('fs');
const path = require('path');
//读取
// htmlUrl = path.join(__dirname,'./练习/练习.html');
// // console.log(htmlUrl);
// cssUrl = path.join(__dirname,'/练习/轮播图.css');
// jsUrl = path.join(__dirname,'/练习/轮播图.js');

//导入http模块，创建服务器
const http = require('http');
const server = http.createServer();
server.on('request',(req,res)=>{
    let url = req.url;
    // const fpath = path.join(__dirname,url);
    let fpath = '';
    if(url == '/'){
        fpath = path.join(__dirname,'/index/index.html')
    }else{
        fpath = path.join(__dirname,'/index',url)
    }
    res.setHeader('Content-Type','text/html; charset=utf-8')
    fs.readFile(fpath,'utf8',(err,data)=>{
        if(err){
            res.end("404 notfind")
        }
            return res.end(data)
        
    })
})
server.listen('8081',()=>{
    console.log('正在访问：http://127.0.0.1:8081');
})